<template>
  <div class="btns-box">
    <div class="left">
      <span v-for="(item, index) in leftBtnList" :key="index">
        <g-btn
          :type="item.type"
          :icon="item.icon"
          :disabled="item.disabled"
          :text="l(item.text)"
          @callback="callback"
          :eventName="item.eventName"
        />
      </span>
    </div>
    <div class="right">
      <div v-for="(item, index) in rightBtnList" :key="index">
        <g-btn
          :type="item.type"
          :icon="item.icon"
          :disabled="item.disabled"
          :text="l(item.text)"
          @callback="callback"
          :eventName="item.eventName"
        />
      </div>
    </div>
  </div>
</template>

<script>
  import GBtn from '/@/shared/components/g-btn/index.vue';
  import AppCompoentBase from '/@/shared/component-base/app-component-base';

  export default {
    name: 'g-btn-group',
    mixins: [AppCompoentBase],
    components: {
      GBtn,
    },
    props: {
      buttonList: {
        //
        default: [],
      },
    },
    data() {
      return {
        clicked: false,
      };
    },
    methods: {
      callback(eventName) {
        if (this.clicked) {
          return;
        }
        this.clicked = true;
        this.$emit('btnCallback', eventName);
        this.clicked = false;
      },
    },
    computed: {
      leftBtnList() {
        return this.buttonList.filter((x) => !x.alignRight && x.display) || [];
      },
      rightBtnList() {
        return this.buttonList.filter((x) => x.alignRight && x.display) || [];
      },
    },
  };
</script>

<style lang="less" scoped>
  @import './g-btn-group.less';
</style>
